
#include "HelloTriangle.h"

#define HELLO_RECTANGLE
bool HelloTriangle::init()
{
	if (!LearnShader::init())	return false;
	std::cout << getChapterName().c_str() << "::" << getNodeName().c_str() << "::init" << std::endl;

	m_pProgram = createProgramWithDefaultPath();

#ifdef HELLO_RECTANGLE
	CREATE_SHADER_ELEMENT_DATA(pElementData, Dataset_Indices_Rectangle);

	CREATE_SHADER_VERTEX_DATA(pVertexData, Dataset_Vertices_Rectangle);
	pVertexData->setVertexSize(3);
	pVertexData->pushVertexAttrib(3, 0);
	m_pVertex = ShaderElementBuffer::create(pElementData, pVertexData);
#else
	CREATE_SHADER_VERTEX_DATA(pVertexData, Dataset_Vertices_Triangle);
	pVertexData->setVertexSize(3);
	pVertexData->pushVertexAttrib(3, 0);
	m_pVertex = ShaderBuffer::create(pVertexData);
#endif // HELLO_RECTANGLE

	return true;
}

void HelloTriangle::release()
{

}

void HelloTriangle::update(float dt)
{
	glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	m_pProgram->use();

	m_pVertex->bindingVertexArray();
#ifdef HELLO_RECTANGLE
	m_pVertex->draw(6);
#else
	m_pVertex->draw(3);
#endif // HELLO_RECTANGLE
	m_pVertex->cleanVertexArray();
	
	swapBuffers();
}